1
開發者提示工程的基礎
AI010Lesson 1
00:00

向指令微調模型的轉變

其基礎是什麼?

過往,基礎型大語言模型主要透過龐大的資料來預測序列中的下一個詞。然而對開發者而言,真正的力量在於指令微調的大語言模型。這些模型透過人類反饋強化學習(RLHF)加以優化,使其能遵循特定指令,並作為得力的助手。

黃金法則:將大語言模型視為一位聰明但字面理解的實習生。它缺乏你的具體背景,因此你必須明確表達目標。

如何應用核心原則

  1. 清晰與精確 清晰不等於簡短。提供更多背景資訊,並使用分隔符(例如三重反引號或 XML 標籤)可幫助模型區分你的指令與它需要處理的資料。
  2. 給予模型思考時間: 複雜任務需要思維鏈。若直接要求模型跳到結論,它更可能產生推理錯誤。應先指示它自行推導解決方案。
避免幻覺
模型可能產生聽起來合理卻錯誤的資訊。務必核實事實,或指示模型引用來源,以降低此風險。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
Why should a developer prefer an Instruction Tuned LLM over a Base LLM for building an application?
Base LLMs are better at following complex instructions.
Instruction Tuned LLMs are trained to follow tasks and are less likely to simply "complete" the text.
Base LLMs never hallucinate.
Challenge: Generating Structured Data
Apply prompting principles to format output.
You have a list of ingredients. You need to convert this list into a JSON format for a web app.
Task
Write a prompt that requests JSON output with keys for 'item' and 'quantity'. Include a condition check: If the input is not a recipe, output "No recipe detected."
Solution:
prompt = "You will be provided with text. If it contains a recipe, convert it to JSON with keys 'item' and 'quantity'. If not, write 'No recipe detected.' Text: <user_input>"